package cms.controller;


import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.ecs.model.v20140526.DescribeInstancesRequest;
import com.aliyuncs.ecs.model.v20140526.DescribeInstancesResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/logup")
public class logup {


    @RequestMapping(value = "/testAliAccount")      //{aliArea}/
    @ResponseBody
    public boolean teatAliAccount(String aliArea,
                                 String aliAccount,
                                 String aliPwd) {


        System.out.println("Logup1");
        Boolean flag=false;

        DefaultProfile profile = DefaultProfile.getProfile(
                aliArea,  aliAccount,aliPwd
  /*            "cn-shenzhen",
                   "LTAI2GvKYQCbRVvq",
                "TLmGqzXDjUuwdoNxKUGKx9IXtgqznF"*/
        );
        System.out.println("Logup2");
        IAcsClient client = new DefaultAcsClient(profile);

        DescribeInstancesRequest request = new DescribeInstancesRequest();
        request.setPageSize(10);

        DescribeInstancesResponse response;
        try {
            response = client.getAcsResponse(request);
            for (DescribeInstancesResponse.Instance instance : response.getInstances()
                    ) {
                System.out.println(instance.getPublicIpAddress());
            }

            flag=true;

        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }

        return flag;
    }

/*    @RequestMapping(value = "/testAliAccount")
    @ResponseBody
    public boolean test(){
        System.out.println("logup--->access");
        return true;
    }*/

}
